<?php
namespace Admin\Controller;
use Admin\Controller\AdminBaseController;
use Common\Model\LeavelModel;
use Common\Model\RewardTypeModel;
use Common\Model\LeavelRatioModel;
class LeavelController extends AdminBaseController{
	public function showlist()
	{
	    $list=LeavelModel::newSelf()->getInfo();
	    $reward_type=RewardTypeModel::newSelf()->getInfo();
	    $this->assign('list',$list);
	    $this->assign('reward_type',$reward_type);
	    $this->display();
	}
	public function update()
	{
	    $id=I('id');
	    $info=LeavelModel::newSelf()->findOneById($id);
	    if (!$info) {
	        $this->error('请选择等级');
	    }
	    $reward_type=RewardTypeModel::newSelf()->getInfo();
	    $this->assign('reward_type',$reward_type);
	    $this->assign('info',$info);
	    $this->display();
	}
	public function updateFormSub()
	{
	    $leavel_id=I('leavel_id');
	    $this->notEmptyValidate($leavel_id,'请选择等级');
        
        $model=LeavelRatioModel::newSelf();
        $leavel=$model->getByLeavelId($leavel_id);
	    $reward_type=RewardTypeModel::newSelf()->getInfo();
        foreach ($reward_type as $k=>$v)
        {
            $ratio=I($v['id']);
            $res=$model->where(['leavel_id'=>$leavel_id,'reward_type'=>$v['id']])->setField($v['type'],$ratio);
        }
        LeavelModel::newSelf()->where(['id'=>$leavel_id])->setField('day_max_reward',I('day_max_reward'));
        $this->returnResult('修改成功',true);
	}
}
